/**
 * 重金属数据实现类
 */
package com.sc.datacollect.imple;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.sc.datacollect.util.Common;
import com.sc.datacollect.util.MongoDb;
import com.sc.datacollect.util.SiteUtil;

public class AirFactor implements IProtocol {
	
	private JSONObject data;
	private MongoDb mongodb;

	public AirFactor(JSONObject data, MongoDb mongodb) {
		this.data = data;
		this.mongodb = mongodb;
	}

	@Override
	public void initData() {
	}
	
	public String saveData() throws Exception {
		String time = String.valueOf(data.get("monitorTime"));
		String tablename = "";
		String ValueType = String.valueOf(data.get("ValueType"));
		if (ValueType.equals("V1Hour")) {
			tablename = "ORI_ITP_AIR_HOUR-" + time.substring(0, 4);
		} else if (ValueType.equals("V1Day_AQI")) {
			tablename = "ORI_ITP_AIR_DAY-" + time.substring(0, 4);
		} else if (ValueType.equals("V5Minute")) {
			tablename = "ORI_ITP_AIR_MIN-" + time.substring(0, 4);
		} else {
			tablename = "ORI_ITP_AIR_MIN-" + time.substring(0, 4);
		}
		
		// 添加站点名称
		data.put("siteName", SiteUtil.getSiteName(data.getString("siteCode"), time));
		mongodb.insert(tablename, JSON.toJSONString(data));
		return Common.SUCCESSCODE;
	}
	
	public String saveTransData() throws Exception {
		String time = String.valueOf(data.get("monitorTime"));
		String tablename = "";
		String ValueType = String.valueOf(data.get("ValueType"));
		if (ValueType.equals("V1Hour")) {
			tablename = "TRS_ITP_AIR_HOUR-" + time.substring(0, 4);
		} else if (ValueType.equals("V1Day_AQI")) {
			tablename = "TRS_ITP_AIR_DAY-" + time.substring(0, 4);
		} else if (ValueType.equals("V5Minute")) {
			tablename = "TRS_ITP_AIR_MIN-" + time.substring(0, 4);
		} else {
			tablename = "TRS_ITP_AIR_MIN-" + time.substring(0, 4);
		}

		// 添加站点名称
		data.put("siteName", SiteUtil.getSiteName(data.getString("siteCode"), time));
		mongodb.insert(tablename, JSON.toJSONString(data));
		return Common.SUCCESSCODE;
	}
}
